QT       +=  core gui widgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17

DEFINES +=
# UNICODE _UNICODE WIN32  WIN64 WINDOWS
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

message("QT_VERSION = $$QT_VERSION")
message("QMAKE_CXX = $$QMAKE_CXX")

message("CONFIG = $$CONFIG")
message("TEMPLATE = $$TEMPLATE")
message("TARGET = $$TARGET")

message("PWD = $$PWD")
message("OUT_PWD = $$OUT_PWD")
message("QT_INSTALL_PREFIX = $$QT_INSTALL_PREFIX")

message("QMAKE_CXX = $$QMAKE_CXX")
message("QMAKE_CC = $$QMAKE_CC")
message("QMAKE_LINK = $$QMAKE_LINK")

message("QMAKE_HOST.os = $$QMAKE_HOST.os")
message("QMAKE_HOST.arch = $$QMAKE_HOST.arch")

defineReplace(GetTimeStamp) {
    win32 {
        return($$system('echo %date% %time%'))
    } else {
        return($$system('date "+%Y-%m-%d %H:%M:%S"'))
    }
}

defineReplace(GetHomeDir) {
    win32 {
        return($$system(echo %USERPROFILE%))
    } else {
        return($$system(echo $HOME))
    }
}

defineReplace(Copy3rdLibToOutput) {
    win32 {
        cmd = copy /Y $$quote($$1) $$quote($$OUT_PWD)
    } else {
        cmd = cp -f $$1 $$OUT_PWD
    }
    return($$cmd $$escape_expand(;) )
}


QMAKE_PATH = $$dirname(QMAKE_QMAKE)
message("QMAKE_QMAKE: $${QMAKE_QMAKE}")
message("QMAKE_PATH: $${QMAKE_PATH}")

message("QMAKE_QMAKE: $${QMAKE_QMAKE}")
QMAKE_PATH = $$replace(QMAKE_QMAKE, /[^/]*$$, )
message("1.QMAKE_PATH: $${QMAKE_PATH}")
QMAKE_PATH = $$replace(QMAKE_QMAKE, /[^/]*$, )
message("2.QMAKE_PATH: $${QMAKE_PATH}")
QMAKE_PATH = $$replace(QMAKE_QMAKE, ^[^/]*/, )
message("3.QMAKE_PATH: $${QMAKE_PATH}")
QMAKE_PATH = $$replace(QMAKE_QMAKE, ^.*/, )
message("4.QMAKE_PATH: $${QMAKE_PATH}")
QMAKE_PATH = $$dirname(QMAKE_QMAKE)
message("5.QMAKE_PATH: $${QMAKE_PATH}")

QMAKE_EXTRA_COMPILERS += asm

SOURCES += src/main.cpp

SOURCES += src/mainwindow.cpp
SOURCES += src/license.cpp
SOURCES += src/pcinfo.cpp
#SOURCES += src/websocketserver.cpp


HEADERS += src/mainwindow.h
HEADERS += src/license.h
HEADERS += src/pcinfo.h
#HEADERS += src/websocketserver.h

FORMS += src/mainwindow.ui

TRANSLATIONS += src/QtLang_en_US.ts
TRANSLATIONS += src/QtLang_zh_CN.ts

CONFIG += lrelease
CONFIG += embed_translations

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

RESOURCES += src/Lang.qrc

BIT7Z_DIR_NAME=bit7z-4.0.9
FREEGLUT_DIR_NAME=freeglut-3.6.0
LIBUSB_DIR_NAME=libusb-1.0.27
LIBUSB_K_DIR_NAME=libusbk-3.1.0.0
LIBUSB_WIN32_DIR_NAME=libusb-win32-src-1.2.6.0
LIBWDI_DIR_NAME=libwdi-1.5.1
SQLITE_DIR_NAME=sqlite-3470200
OPENSSL_DIR_NAME=openssl-master

message("[1] QMAKE_HOST.os : $$QMAKE_HOST.os")

win32 {
    CONFIG += win64
}

DEFINES += __STDC_CONSTANT_MACROS   QT_CORE_LIB QT_GUI_LIB QT_WIDGETS_LIB  _HAS_STD_BYTE=1
INCLUDEPATH = "C:/Program Files (x86)/Windows Kits/10/include" $$INCLUDEPATH  # Windows
INCLUDEPATH += $$[QT_INSTALL_HEADERS]/QtCore

equals(QMAKE_HOST.os, Windows) {
    LIB_HOME_DIR=win64
    #DEFINES += UNICODE _UNICODE _WIN64 _WINDOWS
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000  __STDC_LIMIT_MACROS
    DEFINES += UNICODE   _UNICODE  WIN32 _WIN64  _CONSOLE  __SIZE_T_DEFINED  __STDC_LIMIT_MACROS
    DEFINES +=_ENABLE_EXTENDED_ALIGNED_STORAGE    QT_DEPRECATED_WARNINGS  QCUSTOMPLOT_USE_OPENGL
    DEFINES += BUILD_STATIC
}
equals(QMAKE_HOST.os, linux) {
    LIB_HOME_DIR=linux
}
equals(QMAKE_HOST.os, macx) {
    LIB_HOME_DIR=macos
}

INCLUDEPATH += src

INCLUDEPATH += out/$$LIB_HOME_DIR/$$BIT7Z_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$FREEGLUT_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$LIBUSB_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$LIBUSB_K_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$LIBUSB_WIN32_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$LIBWDI_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$SQLITE_DIR_NAME/include
INCLUDEPATH += out/$$LIB_HOME_DIR/$$OPENSSL_DIR_NAME/include

LIBPATH += out/$$LIB_HOME_DIR/$$BIT7Z_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$FREEGLUT_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$LIBUSB_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$LIBUSB_K_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$LIBUSB_WIN32_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$LIBWDI_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$SQLITE_DIR_NAME/lib
LIBPATH += out/$$LIB_HOME_DIR/$$OPENSSL_DIR_NAME/lib

equals(QMAKE_HOST.os, Windows) {
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$BIT7Z_DIR_NAME/lib/bit7z.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$FREEGLUT_DIR_NAME/lib/freeglut_static.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$LIBUSB_DIR_NAME/lib/libusb_static.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$LIBUSB_K_DIR_NAME/lib/x86/libusbk_static.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$LIBUSB_WIN32_DIR_NAME/lib/x86/libusb0_static.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$LIBWDI_DIR_NAME/lib/libwdi_static.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$SQLITE_DIR_NAME/lib/libsqlite_static.lib

    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$OPENSSL_DIR_NAME/lib/libcrypto-1_1-x64.lib
    LIBS += $$(PWD)/../../out/$$LIB_HOME_DIR/$$OPENSSL_DIR_NAME/lib/libssl-1_1-x64.lib

    LIBS += ws2_32.lib advapi32.lib user32.lib

    CONFIG(debug, debug|release) {
        QMAKE_CXXFLAGS += -MDd  # Debug
        #QMAKE_LFLAGS_DEBUG += /NODEFAULTLIB:library.lib /DEFAULTLIB:msvcrtd.lib
    } else {
        QMAKE_CXXFLAGS += -MD   # Release
        QMAKE_LFLAGS_RELEASE += /NODEFAULTLIB:library.lib /DEFAULTLIB:msvcrt.lib
    }
    QMAKE_CXXFLAGS += /GS-
    for(lib, LIBS_TO_COPY) {
        QMAKE_POST_LINK += $$Copy3rdLibToOutput($$LIBS)
    }
    QMAKE_POST_LINK += $$QMAKE_PATH/windeployqt --dir $$OUT_PWD  debug/$${TARGET}.exe
}
equals(QMAKE_HOST.os, linux) {
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$BIT7Z_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$FREEGLUT_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBUSB_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBUSB_K_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBUSB_WIN32_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBWDI_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$SQLITE_DIR_NAME/lib
}
equals(QMAKE_HOST.os, macx) {
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$BIT7Z_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$FREEGLUT_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBUSB_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBUSB_K_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBUSB_WIN32_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$LIBWDI_DIR_NAME/lib
    LIBS += $$(PWD)/out/$$LIB_HOME_DIR/$$SQLITE_DIR_NAME/lib
}




